<%--
  Created by IntelliJ IDEA.
  User: xiaoyuyu
  Date: 2019/7/3
  Time: 22:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="utf-8">
    <title>
        超市管理系统
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../css/x-admin.css" media="all">
    <%--<link rel="stylesheet" href="../../lib/layui/myicon/iconfont.css" type="text/css">--%>
    <link rel="stylesheet" href="../../lib/layui/myicon/iconfont.css">
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="L_id" class="layui-form-label">
                <span class="x-red">*</span>编码
            </label>
            <div class="layui-input-inline">
                <input type="text" disabled id="L_id" name="id" required="" lay-verify="id"
                       autocomplete="off" class="layui-input" value="">
            </div>

        </div>
        <div class="layui-form-item">
            <label for="L_name" class="layui-form-label">
                名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_name" name="name" required="" lay-verify="name"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_sex" class="layui-form-label">
                性别
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_sex" name="sex" required="" lay-verify="sex"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_birthday" class="layui-form-label">
                生日
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_birthday" name="birthday" required="" lay-verify="birthday"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_telephone" class="layui-form-label">
                电话
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_telephone" name="telephone" required="" lay-verify="telephone"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_address" class="layui-form-label">
                住址
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_address" name="address" required="" lay-verify="address"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_education" class="layui-form-label">
                学历
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_education" name="education" required="" lay-verify="education"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_id_number" class="layui-form-label">
                身份证号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_id_number" name="id_number" required="" lay-verify="id_number"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_duty_time" class="layui-form-label">
                上岗时间
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_duty_time" name="duty_time" required="" lay-verify="duty_time"
                       autocomplete="off" class="layui-input" value="">
                <%--<input type="text" name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">--%>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_duty" class="layui-form-label">
                职务
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_duty" name="duty" required="" lay-verify="duty"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_username" class="layui-form-label">
                <span class="x-red">*</span>用户名
            </label>
            <div class="layui-input-inline">
                <input type="text" disabled id="L_username" name="username" required="" lay-verify="username"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_password" class="layui-form-label">
                密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_password" name="password" required="" lay-verify="password"
                       autocomplete="off" class="layui-input" value="">

            </div>
            <%--<i class="iconfont">&#xe650;</i>--%>
            <%--<a onclick="eye_controll()"><i class="iconfont">&#xe60c;</i></a>--%>
            <button type="button" class="layui-btn layui-btn-danger" onclick="eye_controll()"
                    style="background: #ffffff" id="icon-eye"><span class="iconfont icon-icon-eye-close" style="color: #000;"></span></button>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">启用</label>
            <div class="layui-input-inline">
                <input type="checkbox" checked="" id="L_start_using" name="start_using"
                       lay-skin="switch" lay-filter="start_using" lay-text="ON|OFF">

            </div>
        </div>

        <div class="layui-form-item">
            <button type="button"  class="layui-btn" lay-filter="edit" lay-submit="">
                修改
            </button>
        </div>
    </form>
</div>
<script src="../../lib/layui/layui.js" charset="utf-8">
</script>
<script src="../../js/x-layui.js" charset="utf-8">
</script>
<script src="../../js/jquery.min.js" charset="utf-8"></script>
<script src="../../js/chaoshi.js" charset="utf-8"></script>
<script>
    //请求员工数据
    var employee_data = get_data("${pageContext.request.contextPath}/getEmployeeByUserName",{"username":parent.username});

    //把查询到的数据填到表单中显示
    $("#L_id").val(employee_data.data.id);
    $("#L_name").val(employee_data.data.name);
    $("#L_sex").val(employee_data.data.sex);
    $("#L_birthday").val(employee_data.data.birthday);
    $("#L_telephone").val(employee_data.data.telephone);
    $("#L_address").val(employee_data.data.address);
    $("#L_education").val(employee_data.data.education);
    $("#L_id_number").val(employee_data.data.id_number);
    $("#L_duty_time").val(employee_data.data.duty_time);
    $("#L_duty").val(employee_data.data.duty);
    $("#L_username").val(employee_data.data.username);
    $("#L_password").val(employee_data.data.password);

    //密码显示控制
    function eye_controll(){
        if($("#L_password").attr("type") == "text"){
            $("#L_password")[0].type = "password";
            $("#icon-eye span").removeClass("icon-yanjing");
            $("#icon-eye span").addClass("icon-icon-eye-close");

        }else {
            $("#L_password")[0].type = "text";
            $("#icon-eye span").removeClass("icon-icon-eye-close");
            $("#icon-eye span").addClass("icon-yanjing");


        }
    }

    //日期
    layui.use(['laydate'], function () {
        var laydate = layui.laydate;


        document.getElementById('L_duty_time').onclick = function(){

            laydate({
                elem:this
            });
        };

        document.getElementById('L_birthday').onclick = function(){
            laydate({
                elem:this
            });
        };

    });


    layui.use(['form','layer'], function () {
        var form = layui.form();
        var layer = layui.layer;

        //根据数据初始化开关按钮
        if (employee_data.data.start_using){
            $("#L_start_using").prop("checked",true);
        }else{
            $("#L_start_using").prop("checked",false);
        }
        form.render("checkbox");

        form.on('submit(edit)',function (data) {
            //提交时将数据修改成正确的参数格式
            if(data.field.start_using == "on"){
                data.field.start_using = 1;
            }else{
                data.field.start_using = 0;
            }

            // console.log(JSON.stringify(data.field));

            $.ajax({
                type:"POST",
                url:"${pageContext.request.contextPath}/editEmployee",
                data: data.field,
                async:false,
                success:function (rdata) {

                    if(rdata.code == "1"){
                        // console.log("success");
                        parent.layer.alert("修改成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.replace(parent.location.href);

                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }else{
                        parent.layer.alert("修改失败", {icon: 5});
                        // console.log("failed");
                    }

                }
            });
        });


    });




</script>
</body>

</html>
